<?php defined('SYSPATH') or die('No direct script access.');

class Controller_BoBase extends Controller_Layout {
	protected $modelName = "";
	protected function setTab($view){
		$view->tab_list = $this->tab_list;
		foreach ($this->tab_list as $tab){
			if ($this->request->controller == $tab["controller_name"]){
				$current_tab = $tab;
				break;
			}
		}
		$view->set_global('current_tab', $current_tab);
	}
	
	protected  function baseInfoView($viewPage, $modelName){
		$tmpArray = $_REQUEST;
		if ($viewPage == "home"){
			if (!array_key_exists("page", $tmpArray)){
				$tmpArray["page"] = 1;
			}
		}
		$model = ORM::factory($modelName);
		$model_result = $model->search($tmpArray);
		$view = View::factory("pages/bo/".$viewPage);
		$view->set_global("model_result",$model_result);
		$view->tab_list = $this->tab_list;
		foreach ($this->tab_list as $tab){
			if ($this->request->controller == $tab["controller_name"]){
				$current_tab = $tab;
				break;
			}
		}
		$view->set_global('current_tab', $current_tab);
		$pagination = Pagination::factory(array(
	  		'total_items'    => $model->total_count,
		));
		$page_links = $pagination->render();
		$view->set_global('page_links', $page_links);
		return $view;
	}
	
	public function action_deleteAll(){
		if(ORM::factory($this->modelName)->deleteAll($_REQUEST["ids"])){
			$view = View::factory("pages/bo/common/message_dialog");
			$view->message = "删除成功";
			exit($view->render());
		}
	}
}
